//全部写在一起
//包括react redux 新版的api 
import { createStore } from "redux";
import { Provider, useSelector, useDispatch } from "react-redux";
let state = {
    from: '上海',
    to: '北京',
    isFrom: true,//是否是起始站点击
    showCitySelect: false,//显示
}
//reducer 处理数据的
let reducer = (state, action) => {
    // if(action.type=='add'){
    //     return { ...state, num:state.num+1 }
    // }
    //交换起始站和终点站
    if (action.type == 'exchange') {
        return { ...state, from: state.to, to: state.from }
    }
    //打开/关闭弹框
    if (action.type == 'showCitySelect') {
        //打开才传入 isFrom
        if(String(action.isFrom).length>0){
            return { ...state, showCitySelect: action.value,isFrom:action.isFrom }
        }else{
            return { ...state, showCitySelect: false }
        }
    }
    //设置站点
    if (action.type == 'setCity') {
        if(!!state.isFrom){
            return { ...state,from:action.city }
        }else{
            return { ...state,to:action.city }
        }
    }
    return state;
}
let store = createStore(reducer, state);//第二个参数是state
export default store;